<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>拖拽上传</title>
    <style>
        #drop-area {
            width: 100%;
            min-height: 150px;
            border: 2px dashed #ccc;
            border-radius: 10px;
            padding: 20px;
            box-sizing: border-box;
            text-align: center;
            font-family: Arial, sans-serif;
            cursor: pointer;
        }

        #status {
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div id="drop-area" ondrop="dropHandler(event);" ondragover="dragOverHandler(event);">
    <p>将文件或文件夹拖拽到此处进行上传</p>
</div>
<div id="status"></div>

<script>
    function dragOverHandler(event) {
        event.preventDefault();
        event.dataTransfer.dropEffect = 'copy';
    }

    function dropHandler(event) {
        event.preventDefault();
        var files = event.dataTransfer.files;

        handleFiles(files);
    }

    function handleFiles(files) {
        var status = document.getElementById('status');
        status.innerHTML = '';

        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            status.innerHTML += '<div>上传中: ' + file.name + ' (' + file.size + ' bytes)</div>';

            var formData = new FormData();
            formData.append('file', file);

            var xhr = new XMLHttpRequest();
            xhr.open('POST', '/upload/dd', true);

            xhr.upload.onprogress = function(e) {
                if (e.lengthComputable) {
                    var percentComplete = (e.loaded / e.total) * 100;
                    status.innerHTML += '<div>进度: ' + percentComplete.toFixed(2) + '%</div>';
                }
            };

            xhr.onload = function() {
                status.innerHTML += '<div>上传完成: ' + file.name + '</div>';
            };

            xhr.onerror = function() {
                status.innerHTML += '<div>上传失败: ' + file.name + '</div>';
            };

            xhr.send(formData);
        }
    }
</script>
</body>
</html>
